<template>
  <div class="base-container" id="main">
    <t-steps style="margin-bottom: 14px" :current="activeForm" status="process" :onChange="onCurChanged">
      <t-step-item v-for="(item, index) in stepList" :title="item.title" :key="index" :content="isSubmit(item.id)">
      </t-step-item>
    </t-steps>
    <t-loading text="加载中..." :fullscreen="false" attach="#main" :loading="applyLoading" size="medium">
    </t-loading>
    <div v-if="activeForm === 0">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="填写说明">
            <p>一、填写任务书（合同）之前，请先阅读<a target="_blank"
                href="http://111.75.227.156:20101/view/模板/江西省交通运输厅科技项目管理办法.pdf">《江西省交通运输厅科技项目管理办法》</a>对任务书（合同）内所列各项内容，应实事求是认真填写、明确表述。外来语要同时用原文和中文表达，第一次出现的缩略词，须注明全称。
            </p>
            <p>二、本任务书中规定：委托方（甲方）为厅科技主管部门，承担方（乙方）为项目承担单位，保证方（丙方）为归口管理单位。归口管理单位是项目承担单位的主管部门。</p>
            <p>三、本任务书按表格默认的页面、字体、字号填写；目前标题下若加小标题，则为小四宋体加粗；表格内文字为五号宋体，16磅行距。</p>
            <p>四、本任务书需签字的部分可用钢笔或印章填写，字迹要求工整清楚。各项表格如不够可另加附页。</p>
            <p>五、本任务书正式文本可在江西省交通运输厅科技教育管理系统（http://111.75.227.156:20100/）查看下载。</p>
            <p>六、本任务书附件应包含：承担单位与合作单位的合作协议。</p>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="text-align: center">
        <t-col :span="12">
          <t-space :size="10">
            <t-button theme="primary" @click="onCurChanged(1)">开始任务书签订</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 1">
      <t-form :key="activeForm" labelAlign="top" ref="form" :data="formData1" :rules="rules1"
        class="step-form table-form">
        <t-row>
          <t-col :span="2" class="title">项目编号</t-col>
          <t-col :span="4">
            {{ projectData.projectNum }}
          </t-col>
          <t-col :span="2" class="title"><span class="require">*</span>项目名称</t-col>
          <t-col :span="4">
            <t-form-item label="项目名称：" name="projectName">
              <t-input clearable v-model="formData1.projectName"></t-input>
            </t-form-item>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title"><span class="require">*</span>密 级</t-col>
          <t-col :span="4">
            <t-form-item name="secretLevel">
              <t-radio-group v-model="formData1.secretLevel" :options="dict.type.secret_level"></t-radio-group>
            </t-form-item>
          </t-col>
          <!--          <t-col :span="2" class="title">参加单位总数</t-col>-->
          <!--          <t-col :span="4">{{formData1.itemCompanyList.length}}个</t-col>-->
        </t-row>
        <t-row>
          <t-col :span="2" class="title" style="flex-direction: column">项目承担单位
            <!--            <span style="color:red;">可由单位管理员前往【工作台-系统管理-单位管理】调整</span>-->
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-row>
              <t-col :span="2" class="title">名 称</t-col>
              <t-col :span="10">{{ formData1.declareDeptName }}</t-col>
            </t-row>
            <t-row>
              <t-col :span="2" class="title"><span class="require">*</span>单位所在地</t-col>
              <t-col :span="10">
                <t-form-item name="locationId">
                  <t-cascader clearable filterable :keys="{ value: 'id' }" v-model="formData1.locationId"
                    :options="locationOptions" placeholder="请选择单位所在地"></t-cascader>
                </t-form-item>
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="2" class="title"><span class="require">*</span>通讯地址</t-col>
              <t-col :span="4">
                <t-form-item name="address">
                  <t-input clearable v-model="formData1.address"></t-input>
                </t-form-item>
              </t-col>
              <t-col :span="2" class="title"><span class="require">*</span>邮编</t-col>
              <t-col :span="4">
                <t-form-item name="postCode">
                  <t-input clearable v-model="formData1.postCode"></t-input>
                </t-form-item>
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="2" class="title"><span class="require">*</span>单位性质</t-col>
              <t-col :span="10">
                <t-form-item name="assumeCompanyType">
                  <t-radio-group v-model="formData1.assumeCompanyType"
                    :options="dict.type.assume_company_type"></t-radio-group>
                </t-form-item>
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="2" class="title">归口管理单位</t-col>
              <t-col :span="10">{{ formData1.managerDeptName }}</t-col>
            </t-row>
          </t-col>
        </t-row>
        <!--        <t-row>-->
        <!--          <t-col :span="2" class="title">合作或协作单位-->
        <!--          </t-col>-->
        <!--          <t-col :span="10" style="display:block;">-->
        <!--            <t-row>-->
        <!--              <t-col :span="1" class="title">序号</t-col>-->
        <!--              <t-col :span="11" class="title">单位名称</t-col>-->
        <!--            </t-row>-->
        <!--            <t-row v-for="(item,index) in formData1.itemCompanyList.filter(val=>{return val.type==='2'})" :key="index">-->
        <!--              <t-col :span="1"  style="justify-content: center">{{index+1}}</t-col>-->
        <!--              <t-col :span="11" >{{ item.name }}</t-col>-->
        <!--            </t-row>-->
        <!--          </t-col>-->
        <!--        </t-row>-->
        <t-row>
          <t-col :span="2" class="title">项目负责人
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-row>
              <t-col :span="1" class="title">姓名</t-col>
              <t-col :span="3">{{ projectData.projectLeader.name }}</t-col>
              <t-col :span="1" class="title">性别</t-col>
              <t-col :span="3">{{ projectData.projectLeader.sex | filterByDict(dict.type.sys_user_sex) }}</t-col>
              <t-col :span="1" class="title">出生年月</t-col>
              <t-col :span="3">{{ projectData.projectLeader.birthDate }}</t-col>
            </t-row>
            <t-row>
              <t-col :span="1" class="title">学历</t-col>
              <t-col :span="11">
                {{ projectData.projectLeader.education | filterByDict(dict.type.education) }}
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="1" class="title">职称</t-col>
              <t-col :span="11">
                {{ projectData.projectLeader.profTit | filterByDict(dict.type.prof_tit) }}
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="1" class="title">专业</t-col>
              <t-col :span="3">
                {{ projectData.projectLeader.majorNowName }}
              </t-col>
              <t-col :span="1" class="title">联系电话</t-col>
              <t-col :span="3">{{ projectData.projectLeader.phone }}</t-col>
              <t-col :span="1" class="title">邮箱</t-col>
              <t-col :span="3">{{ projectData.projectLeader.email }}</t-col>
            </t-row>
          </t-col>
        </t-row>
        <!--        <t-row>-->
        <!--          <t-col :span="2" class="title">研究人员人数-->
        <!--          </t-col>-->
        <!--          <t-col :span="10" style="display:block;">-->
        <!--            共 {{formData1?.itemTeam?.totalCount}}   人。其中： 高级： {{formData1?.itemTeam?.highCount}}  人 中级： {{formData1?.itemTeam?.middleCount}} 人 初级： {{formData1?.itemTeam?.primaryCount}} 人 其他： {{formData1?.itemTeam?.auxilian}} 人-->
        <!--          </t-col>-->
        <!--        </t-row>-->
        <t-row>
          <t-col :span="2" class="title">起止时间
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-row>
              <t-col :span="2" class="title"><span class="require">*</span>开始时间</t-col>
              <t-col :span="4">
                <t-form-item name="startDate">
                  <t-date-picker clearable v-model="formData1.startDate"></t-date-picker>
                </t-form-item>
              </t-col>
              <t-col :span="2" class="title"><span class="require">*</span>完成时间</t-col>
              <t-col :span="4">
                <t-form-item name="completeDate">
                  <t-date-picker clearable v-model="formData1.completeDate"></t-date-picker>
                </t-form-item>
              </t-col>
            </t-row>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title">项目类型
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-radio-group v-model="projectData.projectCategory" :disabled="true"
              :options="categoryOptions"></t-radio-group>
            <!--            <t-radio-group disabled v-model="formData1.item.itemType" :options="dict.type.item_type"></t-radio-group>-->
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title"><span class="require">*</span>所属技术领域
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-form-item name="technosphere">
              <t-radio-group v-model="formData1.technosphere"
                :options="dict.type.subject_classification"></t-radio-group>
            </t-form-item>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title"><span class="require">*</span>项目技术来源
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-form-item name="technologySource">
              <t-radio-group v-model="formData1.technologySource"
                :options="dict.type.technology_source"></t-radio-group>
            </t-form-item>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title"><span class="require">*</span>主要研究内容(100字以内)
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-form-item name="mainContent">
              <t-textarea v-model="formData1.mainContent" clearable :maxlength="100" :autosize="{ minRows: 5 }"
                placeholder="请输入内容" />
            </t-form-item>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title">
            <div>
              <p style="text-align:center;width:100%"><span class="require">*</span>预期成果<br /></p>
              <span class="require">(非项目负责人成果)</span>
            </div>
          </t-col>
          <t-col :span="10" class="sub-col">
            <t-row>
              <t-col :span="1" class="title">科技奖励</t-col>
              <t-col :span="11" class="sub-col">
                <t-row>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">国家级</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.awardsGjCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.awardsGjCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">省部级</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.awardsSbCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.awardsSbCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col class="sub-title text-center" :flex="1">专著/论文</t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">中文核心论文</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.cnThesisCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.cnThesisCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">SCI论文</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.sciThesisCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.sciThesisCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">EI论文</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.eiThesisCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.eiThesisCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">ISTP论文</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.istpThesisCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.istpThesisCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">专著</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.treatiseCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.treatiseCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">国际学术奖</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.academicCount">
                          <t-input-number theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.academicCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                </t-row>
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="1" class="title">成果转化</t-col>
              <t-col :span="11" class="sub-col">
                <t-row>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">中试</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.pilotCount">

                          <t-input-number style="width: 100%;" theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.pilotCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">规模化生产</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.scaleCount">
                          <t-input-number style="width: 100%;" theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.scaleCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col class="sub-title text-center" :flex="1">专利</t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">发明专利</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.patentFmCount">
                          <t-input-number style="width: 100%;" theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.patentFmCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">实用新型专利</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.patentSyCount">
                          <t-input-number style="width: 100%;" theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.patentSyCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">其他</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.otherCount">
                          <t-input-number style="width: 100%;" theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.otherCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                  <t-col style="flex-direction: column;padding: 0 !important; border: 0;" :flex="1">
                    <t-row>
                      <t-col :span="12" class="sub-title text-center">标准制（修）定</t-col>
                    </t-row>
                    <t-row>
                      <t-col :span="12">
                        <t-form-item name="contractExpectResults.standardCount">
                          <t-input-number style="width: 100%;" theme="normal" :allowInputOverLimit="false"
                            v-model='formData1.contractExpectResults.standardCount' :min="0"></t-input-number>
                        </t-form-item>
                      </t-col>
                    </t-row>
                  </t-col>
                </t-row>
              </t-col>
            </t-row>
            <!--          </t-col>-->
            <!--        </t-row>-->
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="2" class="title">经费投入
          </t-col>
          <t-col :span="10" style="display:block;">
            <t-row>
              <t-col :span="2" class="title"><span class="require">*</span>总经费</t-col>
              <t-col :span="4"> <t-form-item name="adviceFunding">
                  <t-input-adornment append="万元">
                    <t-input-number :decimal-places="2"
                      @keyup="() => { if (formData1.adviceFunding) { formData1.adviceFunding = Number((formData1.adviceFunding || 0).toString().match(/^\d+(?:\.\d{0,2})?/)) } }"
                      :allowInputOverLimit="false" clearable v-model="formData1.adviceFunding" theme="normal"
                      :min="0"></t-input-number>
                  </t-input-adornment>
                </t-form-item></t-col>
              <t-col :span="2" class="title"><span class="require">*</span>{{ site_tag === 'jtt' ? '厅拨经费' : '集团补助经费'
                }}</t-col>
              <t-col :span="4"> <t-form-item name="subsidyFunding">
                  <t-input-adornment append="万元">
                    <t-input-number
                      :disabled="[1660720633654, 1660720545908, 3782722107465].includes(projectData.projectCategory)"
                      :decimal-places="2"
                      @keyup="() => { if (formData1.subsidyFunding) { formData1.subsidyFunding = Number((formData1.subsidyFunding || 0).toString().match(/^\d+(?:\.\d{0,2})?/)) } }"
                      :allowInputOverLimit="false" clearable v-model="formData1.subsidyFunding" theme="normal"
                      :min="0"></t-input-number>
                  </t-input-adornment>
                </t-form-item></t-col>
            </t-row>
          </t-col>
        </t-row>
      </t-form>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(0)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit1()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 2">
      <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" :data="formData2" :rules="rules2">
        <t-row>
          <t-col :span="12">
            <t-card class="step-card" size="small">
              <template #title>
                1.立项依据、研究内容、目标以及拟解决的关键科学问题（限1000字）<span
                  class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
              </template>
              <t-form-item name="baseContent">
                <tiny-mce-editor :key="`${activeForm}1`" :maxlength="lengthLimitObj.baseContentMax"
                  :textLength.sync="lengthLimitObj.baseContent" v-model="formData2.baseContent"></tiny-mce-editor>
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="12">
            <t-card class="step-card" size="small">
              <template #title>
                2.拟采取的研究方案及可行性分析、本项目的特色与创新之处（限1000字）<span
                  class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
              </template>
              <t-form-item name="approach">
                <tiny-mce-editor :key="`${activeForm}2`" :maxlength="lengthLimitObj.approachMax"
                  :textLength.sync="lengthLimitObj.approach" v-model="formData2.approach"></tiny-mce-editor>
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>
        <t-row>
          <t-col :span="12">
            <t-card class="step-card" size="small">
              <template #title>
                3.预期研究结果及表达形式（限500字）<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
              </template>
              <t-form-item name="achievement">
                <tiny-mce-editor :key="`${activeForm}3`" :maxlength="lengthLimitObj.achievementMax"
                  :textLength.sync="lengthLimitObj.achievement" v-model="formData2.achievement"></tiny-mce-editor>
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>
      </t-form>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(1)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit2()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 3">
      <t-alert style="margin-bottom: 14px" theme="info" title="填表说明：">
        <div slot="message">
          <p class="span-txt">
            1.项目申报时，只需填列项目经费来源和支出的预算数；在项目结题验收时，项目经费来源和支出的预算和决算数均需埴列。
          </p>
          <p>2.“其他”一栏是在与上几栏内容均不相同时具体填写。</p>
          <p>3.直接费用</p>
          <p>（1）设备费： 是指在项目研究开发过程中购置或试制专用仪器设备，对现有仪器设备 进行升级改造， 以及租赁外单位仪器设备而发生的费用。厅拨经费要严格控制设备购置费支出。</p>
          <p>
            （2）业务费：是指在项目实施过程中消耗的各种材料、辅助材料等低值易耗品的采购、运输、装卸、整理等费用，发生的测试化验加工、燃料动力、出版/文献/信息传播/知识产权事务、会议/差旅/国际合作交流等费用，以及其他相关支出。
          </p>
          <p>（3）劳务费： 是指在项目实施过程中支付给参与项目的研究生、博士后、访问学者和项目聘用的研究人员、科研辅助人员等的劳务性费用，以及支付给临时聘请的咨询专家的费用等。</p>
          <p>4.间接费用</p>
          <p>间接费用总额使用分段超额累退比例法计算和控制，按照不超过直接费用扣除设备购置费后的一定比例核定，具体比例如下：500万元及以下部分不超过30％；超过500万元至1000 万元的部分不超过25％；
            超过1000万元的部分不超过20％。</p>
          <p>（1）管理费：是指在项目研究开发过程中对使用本单位现有仪器设备及房屋，日常水、电、气、暖消耗，以及其他有关管理费用的补助支出。</p>
          <p>（2）绩效支出：是指承担项目研究任务的单位为提高科研工作绩效安排的相关支出。有财政拨款补助的单位安排的绩效支出不得超过直接费用扣除设备购置费后的5％。</p>
        </div>
      </t-alert>
      <project-budget v-model="formData3" :projectId="taskId" :editOpen="true" phaseType="3"></project-budget>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(2)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit3()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 4">
      <project-research-plan ref="project-research-plan" v-model="formData4.projectResearchPlan" :projectId="taskId"
        :editOpen="true" phaseType="3"></project-research-plan>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(3)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit4()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 5">
      <project-kpi phaseType="3" :projectId="taskId" ref="project-kpi" v-model="formData5.kpiList"
        :editOpen="true"></project-kpi>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(4)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit5()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 6">
      <t-alert style="margin-bottom: 14px" theme="info" title="填写说明：">
        <div slot="message">
          <p class="span-txt">
            本项目科技成果及其形成的知识产权，其归属、管理和使用按照《交通运输行业知识产权管理办法》的有关规定执行。</p>
          <p class="span-txt">
            （其他约定）
          </p>
        </div>
      </t-alert>
      <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" :data="formData6" :rules="rules6">
        <t-row>
          <t-col :span="12">
            <t-card class="step-card" size="small">
              <template #title>
                成果及其形成的知识产权的归属与保护<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
              </template>
              <t-form-item name="content">
                <tiny-mce-editor :key="`${activeForm}1`" v-model="formData6.content"></tiny-mce-editor>
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>
      </t-form>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(5)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit6()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 7">
      <t-row>
        <t-col :span="12">
          <project-unit ref="project-unit" v-model="formData7.unitList" :projectId="taskId" :editOpen="true"
            phaseType="3"></project-unit>
        </t-col>
      </t-row>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(6)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit7()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 8">
      <t-alert style="margin-bottom: 14px" theme="info" title="填表说明：">
        <div slot="message">
          <p class="span-txt">
            1.青年科技人员数量占比不低于10%；
          </p>
          <p>2.职业教育改革专项、青年科技项目原则上项目负责人应为1名。</p>
          <p>3.青年人员，具有博士学位，年龄在40周岁以下；具有硕士学位、年龄在35周岁以下，女性年龄可适当放宽2周岁，以上年龄截至申报时间上一年度年底。</p>
        </div>
      </t-alert>
      <project-member :show-tip="true" v-model="formData8.memberList" :projectId="taskId" :editOpen="true"
        phaseType="3"></project-member>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(7)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit8()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 9">
      <t-row>
        <t-col :span="12">
          <t-alert v-if="site_tag === 'jtt'" style="margin-bottom: 14px" theme="info" title="固定条款：">
            <div slot="message">
              <p class="span-txt">
                任务书（合同）各方共同遵守《江西省交通运输厅科技项目管理办法》（以下简称《办法》）。</p>
              <p class="span-txt">1．项目承担方（乙方）必须按要求报告项目年度执行情况。</p>
              <p class="span-txt">
                2．项目执行过程中，承担方（乙方）如需调整任务，应根据《办法》中有关规定，向委托方（甲方）提出变更内容及说明的申请报告，经委托方（甲方）审定批准后实施。未接到正式批准书以前，双方应按任务书（合同）履行，否则后果由自行调整的一方负责。
              </p>
              <p class="span-txt">
                3．项目承担方（乙方）因某种原因（如与研究内容有出入、挪用经费、技术措施或实施条件不落实等）致使项目无法执行而要求终止任务，委托方（甲方）可根据调查结果终止研究任务。</p>
              <p class="span-txt">4．项目承担方（乙方）承担项目研究费用按国家科技经费使用管理的相关规定合理开支。</p>
              <p class="span-txt">5．委托方（甲方）根据科技经费的财务管理制度的规定，监督经费的使用情况。</p>
              <p class="span-txt">6．项目执行过程中，委托方（甲方）提出变更任务书（合同）有关内容时，要与承担方（乙方）协商达成书面协议。</p>
              <p class="span-txt">7．本任务书（合同）签订各方均负有相应的责任。若有争议或纠纷时，按科技项目有关管理办法有关条款处理。</p>
              <p class="span-txt">8．任务书（合同）正式文本各方签章后上传厅管理系统留存备查。</p>
            </div>
          </t-alert>
          <t-alert v-else style="margin-bottom: 14px" theme="info" title="固定条款：">
            <div slot="message">
              <p class="span-txt">
                任务书（合同）各方共同遵守《江西省交通投资集团有限责任公司科技创新管理办法》（以下简称《办法》）。</p>
              <p class="span-txt">1．项目承担方（乙方）必须按要求报告项目年度执行情况、下一年度经费预算和有关统计报表，逾期不报，委托方（甲方）有权暂停拨款。</p>
              <p class="span-txt">
                2．项目执行过程中，承担方（乙方）如需调整任务，应根据《办法》中有关规定，向委托方（甲方）提出变更内容及说明的申请报告，经委托方（甲方）审定批准后实施。未接到正式批复以前，双方须按原任务书（合同）履行，否则后果由自行调整的一方负责。
              </p>
              <p class="span-txt">3. 项目承担方（乙方）因某种原因（如与研究内容有出入、挪用经费、技术措施或实施条件不落实等）致使项目无法执行而要求中止任务，委托方（甲方）可根据调查结果中止研究任务。
              </p>
              <p class="span-txt">4．项目承担方（乙方）承担项目所需拨款按国家科技经费使用范围开支。</p>
              <p class="span-txt">5．委托方（甲方）根据科技经费的财务管理制度的规定，监督经费的使用情况。</p>
              <p class="span-txt">6．项目执行过程中，委托方（甲方）提出变更任务书（合同）有关内容时，要与承担方（乙方）协商达成书面协议。</p>
              <p class="span-txt">7．本任务书（合同）签订各方均负有相应的责任。若有争议或纠纷时，按科技项目有关管理办法有关条款处理。</p>
              <p class="span-txt">8．任务书（合同）正式文本委托方（甲方）和第一承担单位（乙方）各存两份、各承担单位和保证方各存一份。</p>
            </div>
          </t-alert>
          <t-card class="step-card" size="small">
            <template #title>
              本任务书（合同）所协议的其他条款如下：<span style="color:red">(如果没有合同条款，可以加一条，内容填“无”)</span>
            </template>
            <!-- <template #title>
                按专家评审意见修改说明：<span style="color: red">必须参照专家意见逐条回复</span>
              </template> -->
            <t-form :key="activeForm" labelAlign="top" ref="form" :data="formData9" :rules="rules9" class="step-form"
              labelWidth="140px">
              <t-form-item name="terms">
                <contract-terms ref="contract-terms" v-model="formData9.terms" :projectId="taskId" :editOpen="true"
                  phaseType="3"></contract-terms>
              </t-form-item>
            </t-form>
          </t-card>

        </t-col>
      </t-row>
      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(8)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit9()">下一步</t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
    <div v-if="activeForm === 10">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <approve-list-by-review-type
            :review-type="![1662099020236, 1660720633654].includes(projectData.projectCategory) ? '4' : '5'"
            :obj-id="taskId"></approve-list-by-review-type>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small">
            <template #title>
              按专家评审意见修改说明：<span style="color: red">必须参照专家意见逐条回复</span><span
                class="textTips-color-red">（如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中）</span>
            </template>
            <t-form :key="activeForm" labelAlign="top" ref="form" :data="formData10" :rules="rules10" class="step-form">
              <t-form-item name="content">
                <tiny-mce-editor :key="activeForm" v-model="formData10.content"></tiny-mce-editor>
              </t-form-item>
            </t-form>
          </t-card>
        </t-col>
      </t-row>

      <t-row style="text-align: center;margin-top: 20px">
        <t-col :span="12">
          <t-space :size="10">
            <t-button @click="onCurChanged(9)" theme="primary" variant="base">上一步
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit10(1)">{{
              applyLoading ? '提交中...' : '暂存'
              }}
            </t-button>
            <t-button theme="primary" :loading="applyLoading" @click="onSubmit10(2)">{{
              applyLoading ? '提交中...' : '提交到单位管理员'
              }}
            </t-button>
          </t-space>
        </t-col>
      </t-row>
    </div>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import TinyMceEditor from "@/components/TinyMceEditor/index.vue";
import dayjs from "dayjs";
import projectMember from "../apply/components/project-member.vue";
import projectBudget from "../apply/components/project-budget.vue";
import projectResearchPlan from "../apply/components/project-research-plan.vue";
import projectKpi from "../apply/components/project-kpi.vue";
import projectUnit from "../apply/components/project-unit.vue";
import contractTerms from "./components/contract-terms.vue";
import approveListByReviewType from "../approve/components/approve-list-by-review-type.vue";
import FileUpload from "@/components/FileUpload/index.vue";
import { getDept } from "@/api/system/dept";


export default {
  name: "contract-apply",
  dicts: ["subject_classification", "kjxm_team", "platform_type", "sys_user_sex", "prof_tit", "degree", "kjxm_key_word", "secret_level", "assume_company_type", "technosphere", "technology_source", "education"],
  components: {
    TinyMceEditor,
    projectMember,
    projectBudget,
    projectResearchPlan,
    projectKpi,
    projectUnit,
    FileUpload,
    contractTerms,
    approveListByReviewType
  },
  data () {
    return {
      file_domain: VITE_FILE_DOMAIN,
      locationOptions: [],
      fundingObj: {},
      lengthLimitObj: {
        digest: 0,
        digestMax: 500,
        baseContent: 0,
        baseContentMax: 1000,
        approach: 0,
        approachMax: 1000,
        achievement: 0,
        achievementMax: 500,
      },
      taskId: null,
      deptMenuOptions: [],
      categoryOptions: [],
      dayjs,
      site_tag: import.meta.env.VITE_SITE_TAG,
      leaderLoading: false,
      linkerLoading: false,
      itemLinkerOptions: [],
      projectLeaderOptions: [],
      planData: {},
      formData1: {
        projectName: '',
        secretLevel: '4',
        assumeCompanyType: '3',
        technosphere: '',
        technologySource: '',
        mainContent: '',
        expectResult: '',
        expectPatent: '',
        expectResultList: [],
        isSubmit: '',
        itemCompanyList: [],
        projectLeader: {},
        attributeDept: {},
        assumeDept: {},
        locationId: null,
        declareDeptName: this.$store.state.user.deptName,
        managerDeptId: null,
        managerDeptName: '',
        contractExpectResults: {
          awardsGjCount: 0,
          awardsSbCount: 0,
          cnThesisCount: 0,
          sciThesisCount: 0,
          eiThesisCount: 0,
          istpThesisCount: 0,
          treatiseCount: 0,
          academicCount: 0,
          pilotCount: 0,
          scaleCount: 0,
          patentFmCount: 0,
          patentSyCount: 0,
          otherCount: 0,
          standardCount: 0,
        },
        address: '',
        postCode: '',
        startDate: '',
        completeDate: '',
        projectId: null,
        adviceFunding: 0,
        subsidyFunding: 0
      },
      rules1: {
        projectName: [
          {
            required: true,
            message: "项目名称不能为空",
          },
        ],
        secretLevel: [
          {
            required: true,
            message: "密级不能为空",
          }
        ],
        locationId: [
          {
            required: true,
            message: "单位所在地不能为空",
          },
        ],
        address: [
          {
            required: true,
            message: "通讯地址不能为空",
          },
        ],
        assumeCompanyType: [
          {
            required: true,
            message: "单位性质不能为空",
          },
        ],
        startDate: [
          {
            required: true,
            message: "开始时间不能为空",
          },
        ],
        completeDate: [
          {
            required: true,
            message: "完成时间不能为空",
          },
          {
            validator: (val) => {
              if (val && this.formData1.startDate) {
                const startTime = new Date(this.formData1.startDate).getTime()
                const endTime = new Date(val).getTime()
                return startTime <= endTime;
              }
              return true;
            }, message: "开始时间不能大于完成时间", type: "error"
          },
        ],
        mainContent: [
          {
            required: true,
            message: "主要研究内容不能为空",
          },
        ],
        adviceFunding: [
          {
            required: true,
            message: "总经费不能为空",
          },
        ],
        subsidyFunding: [
          {
            required: true,
            message: "申请补助经费不能为空",
          },
        ],
      },
      formData2: {
        projectId: null,
        baseContent: '',
        approach: '',
        achievement: '',
      },
      rules2: {
        baseContent: [
          {
            required: true,
            message: "1.立项依据、研究内容、目标以及拟解决的关键科学问题不能为空",
          },
        ],
        approach: [
          {
            required: true,
            message: "2.拟采取的研究方案及可行性分析、本项目的特色与创新之处不能为空",
          },
        ],
        achievement: [
          {
            required: true,
            message: "3.预期研究结果及表达形式不能为空",
          },
        ],
      },
      formData3: {
        phaseType: '3',
        inZcQtczbkBudget: 0,
        inZcDwBudget: 0,
        inZcQtBudget: 0,
        outTbSbBudget: 0,
        outZcSbBudget: 0,
        outTbYwBudget: 0,
        outZcYwBudget: 0,
        outTbLwBudget: 0,
        outZcLwBudget: 0,
        outTbGlBudget: 0,
        outZcGlBudget: 0,
        outTbJxzcBudget: 0,
        outZcJxzcBudget: 0,
      },
      formData4: {
        projectResearchPlan: [],
      },
      formData5: {
        kpiList: []
      },
      formData6: {
        content: '',
      },
      rules6: {
        content: [
          {
            required: true,
            message: "成果及其形成的知识产权的归属与保护不能为空",
          },
        ],
      },
      rules7: {
        reportContent: [
          {
            required: true,
            message: "项目可行性研究报告不能为空",
          },
        ],
      },
      formData7: {
        unitList: []
      },
      formData8: {
        memberList: []
      },
      formData9: {
        terms: []
      },
      rules9: {

      },
      formData10: {
        projectId: null,
        contractId: null,
        content: '',
      },
      rules10: {
        content: [
          {
            required: true,
            message: "按专家评审意见修改说明不能为空",
          },
        ],
      },
      activeForm: 0,
      applyLoading: false,
      stepList: [
        {
          id: 'step0',
          title: '任务书说明',
          require: false,
        },
        {
          id: 'step1',
          title: '项目信息表',
          require: true,
        },
        {
          id: 'step2',
          title: '项目概况',
          require: true,
        },
        {
          id: 'step3',
          title: '项目经费预算',
          require: true,
        },
        {
          id: 'step4',
          title: '项目进度',
          require: true,
        },
        {
          id: 'step5',
          title: '项目绩效目标',
          require: true,
        },
        {
          id: 'step6',
          title: '成果及其形成的知识产权的归属与保护',
          require: true,
        },
        {
          id: 'step7',
          title: '单位信息',
          require: true,
        },
        {
          id: 'step8',
          title: '研究人员',
          require: true,
        },
        {
          id: 'step9',
          title: '共同条款',
          require: true,
        },
        {
          id: 'step10',
          title: '按专家评审意见修改说明',
          require: false,
        },
        // {
        //   id: 'step11',
        //   title: '附件信息',
        //   require: false,
        // },
      ],
      projectData: {
        projectLeader: {}
      }
    }
  },
  watch: {
    activeForm: {
      immediate: true,
      handler (val) {
        // this.$refs.form?.clearValidate();
        this.oldUser = null;
        // document.getElementsByClassName("t-layout__content").scrollTop;
        const targetEle = document.getElementsByClassName("base-container")[0]
        if (targetEle) {
          const { pos, top } = targetEle.style;
          targetEle.style.position = 'relative';
          targetEle.style.top = '-100px';
          targetEle.scrollIntoView({ behavior: 'smooth', block: 'start', inline: "nearest" });
          targetEle.style.top = top;
          targetEle.style.position = pos;
        }
        // document.getElementById("main").scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"})
      }
    }
  },
  async created () {
    const taskId = this.$route.params && this.$route.params.taskId;
    if (!taskId) {
      this.$message.error("任务id丢失返回项目");
      this.$router.push("/kjxm/contract/contract-my");
      return false;
    }
    this.taskId = taskId;
    const activeForm = Number(sessionStorage.getItem(`${taskId}-kjxm-contract-activeForm`)) || 0;

    this.getPlanCategoryList();
    this.getLocationTree();
    await this.getDept();
    await this.getManagerDeptById();
    await this.getProject();
    this.onCurChanged(activeForm)
  },
  methods: {
    getDept () {
      // 获取承担单位
      getDept(this.$store.state.user.deptId).then(response => {
        this.formData1.address = this.formData1.address || response.data.address;
        this.formData1.locationId = this.formData1.locationId || response.data.locationId;
        this.formData1.postCode = this.formData1.postCode || response.data.postCode;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getProject () {
      return this.$api.kjxm.project.getNewAll(this.taskId).then(pro => {
        this.projectData = pro.data;
        this.formData1.startDate = pro.data.startDate;
        this.formData1.completeDate = pro.data.endDate;
        this.formData1.projectName = pro.data.projectName;
        this.formData1.technosphere = pro.data.subjectClassification;
        this.formData1.adviceFunding = pro.data.adviceFunding;
        this.formData1.subsidyFunding = pro.data.subsidyFunding;
        Object.assign(this.formData2, pro.data.projectOverview);
        if (Object.prototype.hasOwnProperty.call(this.formData2, "id")) {
          delete this.formData2.id;
        }
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    getManagerDeptById () {
      return this.$api.system.dept.getManagerDeptById(this.$store.state.user.deptId).then(response => {
        this.formData1.managerDeptId = this.formData1.managerDeptId || response.data.id;
        this.formData1.managerDeptName = this.formData1.managerDeptName || response.data.deptName;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getLocationTree () {
      return this.$api.system.location.treeselect().then(response => {
        this.locationOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getPlanCategoryList () {
      this.$api.kjxm.project.planCategoryList(this.queryParams).then(
        (res) => {
          const projectCategoryData = res.data.filter((val) => {
            if (!val.parentId) { return true }
          })
          this.projectCategoryData = projectCategoryData;
          this.categoryOptions = projectCategoryData.map((val) => ({ label: val.name, value: val.id }))
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
    },
    isSubmit (name) {
      if (name === "step0") {
        return ""
      }
      return sessionStorage.getItem(`${this.taskId}-kjxm-contract-${name}`) ? '已提交' : '未提交';
    },
    onCurChanged (cur, pre) {
      if (![0, 1].includes(cur)) {
        if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)) {
          this.applyLoading = false;
          this.$message.error("基本信息还未提交")
          return false;
        }
      }
      this.applyLoading = true;
      // 根据不同的activeForm 复查数据
      if (Number(cur) === 1) {
        if (sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)) {
          const objId = Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`));
          this.$api.kjxm.contract.getByProject(this.taskId).then(response => {
            if (response.data) {
              Object.assign(this.formData1, response.data)
            }
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 2) {
        if (sessionStorage.getItem(`${this.taskId}-kjxm-contract-step2`)) {
          const objId = Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step2`));
          this.$api.kjxm.contract.contractOverviewGet(objId).then(response => {
            Object.assign(this.formData2, response.data);
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 6) {
        if (sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)) {
          const objId = Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`));
          this.$api.kjxm.contract.ResultsGetByContractId(objId).then(response => {
            Object.assign(this.formData6, response.data);
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 9) {
        const objId = Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`));
        this.$api.kjxm.contract.termsGetByContractId(objId).then(response => {
          this.formData9.terms = response.data;
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
          this.applyLoading = false;
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      }
      else if (Number(cur) === 10) {
        const objId = Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`));
        this.$api.kjxm.contract.projectContractExplainGetByContractId(objId).then(response => {
          if (response.data) {
            Object.assign(this.formData10, response.data)
          }
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
          this.applyLoading = false;
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      }
      else {
        this.activeForm = cur;
        sessionStorage.setItem(`${this.taskId}-kjxm-contract-activeForm`, cur);
        this.applyLoading = false;
      }
    },
    onSubmit1 () {
      this.$refs.form.validate().then((validateResult) => {
        if (validateResult === true) {
          if (Number(this.formData1.adviceFunding) < Number(this.formData1.subsidyFunding)) {
            const label = this.site_tag === 'jtt' ? '厅拨经费' : '集团补助经费';
            this.$message.error(`总经费:${this.formData1.adviceFunding}不能小于${label}:${this.formData1.subsidyFunding}`);
            return false
          }
          this.applyLoading = true;
          this.formData1.projectId = this.taskId;
          if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)) {
            this.$api.kjxm.contract.add(this.formData1).then(response => {
              sessionStorage.setItem(`${this.taskId}-kjxm-contract-step1`, response.data.id)
              this.$message.success('提交成功');
              this.onCurChanged(2);
            }).catch((e) => {
              this.applyLoading = false;
              this.$message.error(e.toString());
            });
          } else {
            this.$api.kjxm.contract.update(this.formData1).then(response => {
              this.$message.success('提交成功');
              this.onCurChanged(2);
            }).catch((e) => {
              this.applyLoading = false;
              this.$message.error(e.toString());
            });
          }
        } else {
          const firstError = Object.values(validateResult)[0]?.[0]?.message;
          this.$message.error(firstError);
        }
      });
    },
    onSubmit2 () {
      this.$refs.form.validate().then((validateResult) => {
        if (validateResult === true) {

          if (this.lengthLimitObj.baseContent > this.lengthLimitObj.baseContentMax) {
            this.$message.error(`1.立项依据、研究内容、目标以及拟解决的关键科学问题： 当前字数：${this.lengthLimitObj.baseContent}，限制字数：${this.lengthLimitObj.baseContentMax}`)
            return false;
          }
          if (this.lengthLimitObj.approach > this.lengthLimitObj.approachMax) {
            this.$message.error(`2.拟采取的研究方案及可行性分析、本项目的特色与创新之处： 当前字数：${this.lengthLimitObj.approach}，限制字数：${this.lengthLimitObj.achievementMax}`)
            return false;
          }
          if (this.lengthLimitObj.achievement > this.lengthLimitObj.achievementMax) {
            this.$message.error(`2.拟采取的研究方案及可行性分析、本项目的特色与创新之处： 当前字数：${this.lengthLimitObj.achievement}，限制字数：${this.lengthLimitObj.achievementMax}`)
            return false;
          }

          if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step2`)) {
            this.$api.kjxm.contract.contractOverviewAdd({
              ...this.formData2,
              projectId: this.taskId
            }).then(response => {
              sessionStorage.setItem(`${this.taskId}-kjxm-contract-step2`, response.data.id)
              this.$message.success('提交成功');
              this.onCurChanged(3);
            }).catch((e) => {
              this.applyLoading = false;
              this.$message.error(e.toString());
            });
          } else {
            this.$api.kjxm.contract.contractOverviewUpdate({
              ...this.formData2,
              projectId: this.taskId
            }).then(response => {
              this.$message.success('提交成功');
              this.onCurChanged(3);
            }).catch((e) => {
              this.applyLoading = false;
              this.$message.error(e.toString());
            });
          }
        } else {
          const firstError = Object.values(validateResult)[0]?.[0]?.message;
          this.$message.error(firstError);
        }
      })
    },
    onSubmit3 () {
      // 判断经费来源 经费支出 是否一致
      const sum1 = (Number(((this.formData3.inTbBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.inZcBudget || 0) * 100).toFixed(2))) / 100;
      const sum2 = (Number(((this.formData3.outTbSbBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outTbYwBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outTbLwBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outTbGlBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outTbJxzcBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outZcSbBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outZcYwBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outZcLwBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outZcGlBudget || 0) * 100).toFixed(2)) + Number(((this.formData3.outZcJxzcBudget || 0) * 100).toFixed(2))) / 100;

      if (sum1 !== sum2) {
        this.$message.error('经费来源与经费支出金额不一致');
        return false;
      }
      this.applyLoading = true;
      if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step4`)) {
        this.$api.kjxm.project.budgetAdd({
          ...this.formData3,
          projectId: this.taskId
        }).then(response => {
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-step3`, response.data.id);
          this.$message.success('提交成功');
          this.onCurChanged(4)
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      } else {
        this.$api.kjxm.project.budgetEdit({
          ...this.formData3,
          projectId: this.taskId,
        }).then(response => {
          this.$message.success('提交成功');
          this.onCurChanged(4)
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      }
    },
    onSubmit4 () {
      if (this.formData4.projectResearchPlan.length <= 0) {
        this.$message.error('项目进度不能为空');
        return false;
      }
      const isValidate = this.$refs["project-research-plan"].checkData()
      if (!isValidate) {
        return false;
      }
      this.applyLoading = true;
      this.$api.kjxm.project.researchPlanAdd(this.formData4.projectResearchPlan).then(response => {
        this.$message.success('提交成功');
        sessionStorage.setItem(`${this.taskId}-kjxm-contract-step4`, this.formData4.projectResearchPlan.length);
        this.onCurChanged(5)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit5 () {
      if (this.formData5.kpiList.length <= 0) {
        this.$message.error('项目绩效指标不能为空');
        return false;
      }
      const isValidate = this.$refs["project-kpi"].checkData()
      if (!isValidate) {
        return false;
      }
      this.applyLoading = true;
      this.$api.kjxm.project.projectExpectResultsAddOrUpdate(this.formData5.kpiList).then(response => {
        this.$message.success('提交成功');
        sessionStorage.setItem(`${this.taskId}-kjxm-contract-step5`, this.formData5.kpiList.length);
        this.onCurChanged(6)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit6 () {
      this.applyLoading = true;
      if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step6`)) {
        this.$api.kjxm.contract.ResultsAdd({
          ...this.formData6,
          contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
          projectId: this.taskId,
        }).then(response => {
          sessionStorage.setItem(`${this.taskId}-kjxm-contract-step6`, response.data.id)
          this.$message.success('提交成功');
          this.onCurChanged(7)
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      } else {
        this.$api.kjxm.contract.ResultsUpdate({
          ...this.formData6,
          id: sessionStorage.getItem(`${this.taskId}-kjxm-contract-step6`),
          contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
          projectId: this.taskId,
        }).then(response => {
          this.$message.success('提交成功');
          this.onCurChanged(7)
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      }
    },
    onSubmit7 () {
      const isValidate = this.$refs["project-unit"].checkData()
      if (!isValidate) {
        return false;
      }
      this.applyLoading = true;
      this.$api.kjxm.project.companyAdd(this.formData7.unitList).then(response => {
        this.$message.success('提交成功');
        sessionStorage.setItem(`${this.taskId}-kjxm-contract-step7`, this.formData7.unitList.length)
        this.onCurChanged(8)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit8 () {
      // 需要判断必填
      const data1 = this.formData8.memberList.filter((val) => ['1', '2'].includes(val.type));
      const data2 = this.formData8.memberList.filter((val) => val.type === '3');
      if (data1.length <= 0) {
        this.$message.error('项目负责人不能为空');
        return
      }
      this.applyLoading = true;
      this.$api.kjxm.project.memberAdd(this.formData8.memberList).then(response => {
        this.$message.success('提交成功');
        sessionStorage.setItem(`${this.taskId}-kjxm-contract-step8`, this.formData8.memberList.length)
        this.onCurChanged(9)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit9 () {
      const isValidate = this.$refs["contract-terms"].checkData()
      if (!isValidate) {
        return false;
      }
      this.applyLoading = true;
      this.formData9.terms = this.formData9.terms.map(val => ({ ...val, contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)) }))
      this.$api.kjxm.contract.TermsAdd(this.formData9.terms).then(response => {
        this.$message.success('提交成功');
        sessionStorage.setItem(`${this.taskId}-kjxm-contract-step9`, this.formData9.terms.length)
        this.onCurChanged(10)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit10 (type) {
      if (type === 1) {
        this.applyLoading = true;
        if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step10`)) {
          this.$api.kjxm.contract.projectContractExplainAdd({
            ...this.formData10,
            projectId: this.taskId,
            contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
          }).then(response => {
            this.$message.success('提交成功');
            sessionStorage.setItem(`${this.taskId}-kjxm-contract-step10`, response.data.id)
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.contract.projectContractExplainUpdate({
            ...this.formData10,
            id: sessionStorage.getItem(`${this.taskId}-kjxm-contract-step10`),
            projectId: this.taskId,
            contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
          }).then(response => {
            this.$message.success('提交成功');
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }
      } else {
        this.$refs.form.validate().then((validateResult) => {
          if (validateResult === true) {
            this.stepList.forEach((val) => {
              if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-${val.id}`) && val.require) {
                this.$message.error(`${val.title}还未提交`)
                this.applyLoading = false;
                return false;
              }
            })
            this.applyLoading = true;
            if (!sessionStorage.getItem(`${this.taskId}-kjxm-contract-step10`)) {
              this.$api.kjxm.contract.projectContractExplainAdd({
                ...this.formData10,
                projectId: this.taskId,
                contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
              }).then(response => {
                sessionStorage.setItem(`${this.taskId}-kjxm-contract-step10`, response.data.id)
                this.applyLoading = false;
                this.onSubmit()
              }).catch((e) => {
                this.applyLoading = false;
                this.$message.error(e.toString());
              });
            } else {
              this.$api.kjxm.contract.projectContractExplainUpdate({
                ...this.formData10,
                id: sessionStorage.getItem(`${this.taskId}-kjxm-contract-step10`),
                projectId: this.taskId,
                contractId: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
              }).then(response => {
                this.applyLoading = false;
                this.onSubmit();
              }).catch((e) => {
                this.applyLoading = false;
                this.$message.error(e.toString());
              });
            }
          } else {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            this.$message.error(firstError);
          }
        });
      }
    },
    onSubmit () {
      const confirmDia = this.$dialog.confirm({
        header: "提交后不可再编辑会进入审批流程",
        body: `是否确认提交？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.applyLoading = true;
          this.$api.kjxm.contract.submit({
            id: Number(sessionStorage.getItem(`${this.taskId}-kjxm-contract-step1`)),
          }).then(response => {
            this.applyLoading = false;
            confirmDia.destroy();
            this.$message.success('提交成功');
            this.close();
          }).catch((e) => {
            this.applyLoading = false;
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        },
      })
    },
    close () {
      this.$tab.closeOpenPage({ path: this.$route.meta.activeMenu || "/kjxm/contract/project-my" });
    },
  }
}
</script>

<style lang="less" scoped>
.base-container {
  .t-row {
    margin-bottom: 14px;
  }

  .step-card {
    p {
      font-size: 16px;
    }
  }
}
</style>
